package spotGUI.utils;

import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;

import personalProfile.FamilyManager.FamilyComponent;


public class FamilyListCellRenderer implements ListCellRenderer {

	private DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {

		JLabel listCellRendererComponent = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

		return getPersonLabel((FamilyComponent)value, listCellRendererComponent);

	}

	private JLabel getPersonLabel (FamilyComponent data, JLabel label) {
		
		
		String name = data.name;
		ImageIcon photo = data.photo;
			
		//label.setBorder(new EtchedBorder(EtchedBorder.RAISED));
		label.setVerticalTextPosition(SwingConstants.BOTTOM);
		label.setHorizontalTextPosition(SwingConstants.CENTER);
		label.setOpaque(false);
		
		
		label.setText(name);
		if (photo != null)
			label.setIcon(photo);
		else
			label.setIcon(new ImageIcon(FamilyListCellRenderer.class.getResource("/images/Icons/128x128/user.png")));
		return label;
	}
	
}